//
//  MPlusMainViewController.m
//  medicineplus
//
//  Created by gufei on 15-4-9.
//  Copyright (c) 2015年 chn_ruby@126.cn. All rights reserved.
//

#import "MPlusMainViewController.h"
#import "MPlusHumanitiesListViewController.h"
#import "MPlusMedicineBaikeViewController.h"
#import "AdView.h"
#import "MPlusDefine.h"
#import "MPlusString.h"

@interface MPlusMainViewController () {
    AdView * adView;
}

@end

@implementation MPlusMainViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self setTabBarResource:kTabBarTitleMain setImage:kTabBarImageMain setSelectedImage:kTabBarSelectedImageMain];
        [self setNavigationTitle:kNavTitleMain];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self createScrollView];
    [self createMenuIndicator];
}

#pragma mark - create ads scrollview
- (void)createScrollView {
    NSArray *imagesURL = @[
                           @"https://ss0.baidu.com/7Po3dSag_xI4khGko9WTAnF6hhy/super/whfpf%3D425%2C260%2C50/sign=ad5c5c610fd162d985bb315c77e29dde/50da81cb39dbb6fdfd32f7830c24ab18972b372d.jpg",
                           @"http://a.hiphotos.baidu.com/image/w%3D310/sign=2a2b2eaa79f40ad115e4c1e2672d1151/eaf81a4c510fd9f9f77a4cfb272dd42a2834a436.jpg",
                           @"http://a.hiphotos.baidu.com/image/w%3D310/sign=e0999b89357adab43dd01d42bbd5b36b/54fbb2fb43166d2257ca3d35452309f79152d2d5.jpg"
                           ];
    
    // 情景三：图片配文字(可选)
    NSArray *titles = @[@"AAOS 单髓内钉效果最好",
                        @"AAOS 单髓内钉效果最好",
                        @"AAOS 单髓内钉效果最好",
                        ];
    
    //如果你的这个广告视图是添加到导航控制器子控制器的View上,请添加此句,否则可忽略此句
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    adView = [AdView adScrollViewWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, 180) imageLinkURL:imagesURL placeHoderImageName:@"placeHoder.jpg" pageControlShowStyle:UIPageControlShowStyleLeft];
    
    //    是否需要支持定时循环滚动，默认为YES
    //    adView.isNeedCycleRoll = YES;
    
    [adView setAdTitleArray:titles withShowStyle:AdTitleShowStyleRight];
    //    设置图片滚动时间,默认3s
    //    adView.adMoveTime = 2.0;
    
    //图片被点击后回调的方法
    adView.callBack = ^(NSInteger index,NSString * imageURL) {
        
    };
    [self.view addSubview:adView];
}

- (void)createMenuIndicator {
    // E+培训
    UIButton *eplusEduBtn = [[UIButton alloc] init];
    [eplusEduBtn setBackgroundImage:[UIImage imageNamed:@"ic_eplus.png"] forState:UIControlStateNormal];
    eplusEduBtn.frame = CGRectMake(5, 249, SCREEN_WIDTH * 0.36, 180);
    eplusEduBtn.tag = 100;
    [eplusEduBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:eplusEduBtn];
    
    // 医学百科
    UIButton *medicineBaikeBtn = [[UIButton alloc] init];
    [medicineBaikeBtn setBackgroundImage:[UIImage imageNamed:@"ic_baike.png"] forState:UIControlStateNormal];
    medicineBaikeBtn.frame = CGRectMake(5, 249 + 180 + 5, SCREEN_WIDTH * 0.36, 180);
    medicineBaikeBtn.tag = 200;
    [medicineBaikeBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:medicineBaikeBtn];
    
    // 人文医学
    UIButton *humanitiesBtn = [[UIButton alloc] init];
    [humanitiesBtn setBackgroundImage:[UIImage imageNamed:@"ic_hum.png"] forState:UIControlStateNormal];
    humanitiesBtn.frame = CGRectMake(5 * 2 + SCREEN_WIDTH * 0.36, 249, SCREEN_WIDTH - SCREEN_WIDTH * 0.36 - 5 * 3, (180 * 2 + 5 - 5 * 2)/3);
    humanitiesBtn.tag = 300;
    [humanitiesBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:humanitiesBtn];
    
    // 免费体检
    UIButton *freeCheckBtn = [[UIButton alloc] init];
    [freeCheckBtn setBackgroundImage:[UIImage imageNamed:@"ic_freecheck.png"] forState:UIControlStateNormal];
    freeCheckBtn.frame = CGRectMake(5 * 2 + SCREEN_WIDTH * 0.36, 249 + (180 * 2 + 5 - 5 * 2)/3 + 5, SCREEN_WIDTH - SCREEN_WIDTH * 0.36 - 5 * 3, (180 * 2 + 5 - 5 * 2)/3);
    freeCheckBtn.tag = 400;
    [freeCheckBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:freeCheckBtn];
    
    // 帮助中心
    UIButton *helpCenterBtn = [[UIButton alloc] init];
    [helpCenterBtn setBackgroundImage:[UIImage imageNamed:@"ic_help.png"] forState:UIControlStateNormal];
    helpCenterBtn.frame = CGRectMake(5 * 2 + SCREEN_WIDTH * 0.36, 249 + 2 * (180 * 2 + 5 - 5 * 2)/3 + 5 * 2, SCREEN_WIDTH - SCREEN_WIDTH * 0.36 - 5 * 3, (180 * 2 + 5 - 5 * 2)/3);
    helpCenterBtn.tag = 500;
    [helpCenterBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:helpCenterBtn];
}

- (void)btnClick:(UIButton *)btn {
    
    if (btn.tag == 100) {
        
    } else if (btn.tag == 200) {
        MPlusMedicineBaikeViewController *ctrl = [[MPlusMedicineBaikeViewController alloc] initWithNibName:nil bundle:nil];
        [self.navigationController pushViewController:ctrl animated:YES];
    } else if (btn.tag == 300) {
        MPlusHumanitiesListViewController *ctrl = [[MPlusHumanitiesListViewController alloc] initWithNibName:nil bundle:nil];
        [self.navigationController pushViewController:ctrl animated:YES];
    } else if (btn.tag == 400) {
        
    } else if (btn.tag == 500) {
        
    }
    
}
          
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
